// adapter constants, endian-specific conversions etc...

#ifndef ADAPTER_H
#define ADAPTER_H

#include "pci.h"

// 4 numbers into an internet addy
#define inetAddress(_a_,_b_,_c_,_d_) ( _a_|(_b_<<8)|(_c_<<16)|(_d_<<24) )

// gets part of an internet addy
#define IPAddr0( _a_ ) ( _a_ & 0xFF )
#define IPAddr1( _b_ ) ( ( _b_ >> 8 ) & 0xFF )
#define IPAddr2( _c_ ) ( ( _c_ >> 16 ) & 0xFF )
#define IPAddr3( _d_ ) ( ( _d_ >> 24 ) & 0xFF )

// hard ware address
struct netHwAddr_t
{
	uint32_t type;
	uint32_t dataSize;
	union
	{
		uint8_t ethernet[6];
		uint8_t raw[1];
	} u;
};

// network adapter
typedef struct _netAdapter_t
{
	/* General Info */
	int up;
	int type;
	struct netHwAddr_t *hwaddr;
	void *data;
	uint32_t mtu;
	uint32_t overhead;

	/* stuff for IP */
	uint32_t ipaddr;
	uint32_t netmask;
	uint32_t broadcast;
	uint32_t network;
	uint32_t gateway;
	uint32_t dns;
	void *packetCache;

	/* stuff for reporting */
	uint32_t dropped;
	uint32_t errors;
	uint32_t received;
} netAdapter_t;

// config structure
typedef struct _ifconfig_t
{
	uint32_t ipaddr;
	uint32_t netmask;
	uint32_t broadcast;
	uint32_t network;
	uint32_t gateway;
	uint32_t dns;
	uint32_t mtu;
} ifconfig_t;

// ethernet type
#define NET_TYPE_ETHER 1

// network to host short
#define ntohs(n) ( (((n) & 0xFF00) >> 8) | (((n) & 0x00FF) << 8) )
// host to network short
#define htons(n) ( (((n) & 0xFF00) >> 8) | (((n) & 0x00FF) << 8) )

// network to host long
#define ntohl(n) ( (((n) & 0xFF000000) >> 24) | (((n) & 0x00FF0000) >> 8) | (((n) & 0x0000FF00) << 8) | (((n) & 0x000000FF) << 24) )
// host to network long
#define htonl(n) ( (((n) & 0xFF000000) >> 24) | (((n) & 0x00FF0000) >> 8) | (((n) & 0x0000FF00) << 8) | (((n) & 0x000000FF) << 24) )

#endif
